package concurrent;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ConcurrentClass {

	private HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

	private ExecutorService service = Executors.newCachedThreadPool();

	public static void main(String[] args) {
		final ConcurrentClass concurrentClass = new ConcurrentClass();
		for (int i = 0; i < 6; i++) {
			final int j = i;
			concurrentClass.service.submit(new Runnable() {

				@Override
				public void run() {
					int m = 1;
					while (true) {
						if (m++ > 10)
							break;
//						System.out.println(Thread.currentThread().getName() + j * 1000);
						concurrentClass.map.put(j * 100, j * 1000);
						try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
				}
			});
		}
		concurrentClass.service.shutdown();
		System.out.println(concurrentClass.map.size());
	}
}
